package com.rayo.accesscontrollercopy.model.db.dao;

import com.litesuits.orm.db.assit.QueryBuilder;
import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.KeyBoxData;

import java.util.List;

/**
 * Created by zxy on 2018/9/27.
 */

public class KeyBoxImpl implements KeyBoxDao {
    @Override
    public void addKeyBox(KeyBoxData keyBoxData) {
        DbHelp.insert(keyBoxData);
    }

    @Override
    public List<KeyBoxData> findAll() {
        return DbHelp.getQueryAll(KeyBoxData.class);
    }

    @Override
    public KeyBoxData findById(byte id) {
        QueryBuilder qb = new QueryBuilder(KeyBoxData.class).whereEquals(KeyBoxData.ID,id);
        List<KeyBoxData> list = DbHelp.liteOrm.query(qb);
        if (null == list || list.isEmpty()) return null;
        else return list.get(0);
    }

    @Override
    public void updataKeyBox(KeyBoxData keyBoxData) {
        DbHelp.update(keyBoxData);
    }

    @Override
    public void deleteKeyBox(byte i) {
        DbHelp.deleteWhere(KeyBoxData.class,"keyboxId",new String[]{String.valueOf((int)i)});
    }
}
